package com.oppo.action;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.commons.dbutils.handlers.BeanListHandler;

import com.alibaba.fastjson.JSON;
import com.oppo.bean.OrderProductBean;
import com.oppo.db.BasicDataOperation;
import com.oppo.tools.MyTools;

@WebServlet("/OrderAction")
public class OrderAction extends HttpServlet {
	private static final long serialVersionUID = 1L;
  
	protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		request.setCharacterEncoding("utf-8");
		response.setCharacterEncoding("utf-8");
		String sql_query = "SELECT * FROM order_t o,product_t p WHERE o.product_id = p.product_id AND user_id = " + request.getParameter("user_id");
		List<OrderProductBean> list = MyTools.getNewInstance(BasicDataOperation.class).queryData(sql_query, new BeanListHandler<>(OrderProductBean.class));
		
		String strJson = JSON.toJSONString(list);
		PrintWriter pw = response.getWriter();
		// 将json字符串发回客户端浏览器
		pw.write(strJson);
		pw.flush();
		pw.close();
		
	}

}
